/*
 * MainFrame.java
 *
 * Created on April 18, 2007, 12:45 PM
 */

package org.wii.jadwal.gui;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import org.wii.jadwal.model.Jadwal;
import org.wii.jadwal.model.JadwalManager;

/**
 *
 * @author  Hendro
 */
public class MainFrame extends javax.swing.JFrame {
    List listJadwalHariIni = new ArrayList();
    List listJadwalByKeyword = new ArrayList();
    List listJadwalByDate = new ArrayList();
    JadwalManager mgr = new JadwalManager();
    /** Creates new form MainFrame */
    public MainFrame() {
        initComponents();
        loadJadwalHariIni();
    }
    
    private void loadJadwalHariIni(){
        try {
            listJadwalHariIni = mgr.listAllJadwalHariIni();
        } catch (Exception ex) {
            JOptionPane.showConfirmDialog(this,"Ups! telah terjadi Error");
            ex.printStackTrace();
        }
        String[][] data = new String[listJadwalHariIni.size()][3];
        for(int x=0;x<listJadwalHariIni.size();x++){
            Jadwal jd = (Jadwal)listJadwalHariIni.get(x);
            data[x][0] = jd.getKeyword();
            data[x][1] = jd.getTitle();
            if(jd.getStatus()==0) data[x][2]="Not Complete";
            else data[x][2] = "Completed";
        }
        String[] title = {"Kata Kunci","Title","Status"};
        DefaultTableModel model = new DefaultTableModel(data,title);
        tblJadwalHariIni.setModel(model);
        jScrollPane1.setViewportView(tblJadwalHariIni);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblJadwalHariIni = new javax.swing.JTable();
        jButton3 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        tglWarningDate = new org.jdesktop.swingx.JXDatePicker();
        txtKataKunci = new javax.swing.JTextField();
        txtJudul = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtKonten = new javax.swing.JTextArea();
        btnSimpan = new javax.swing.JButton();
        btnBaru = new javax.swing.JButton();
        btnBatal = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jTabbedPane2 = new javax.swing.JTabbedPane();
        jPanel5 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        txtKeyword = new javax.swing.JTextField();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblJadwalByKeyword = new javax.swing.JTable();
        btnCari = new javax.swing.JButton();
        btnDetailByKey = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        tglAwal = new org.jdesktop.swingx.JXDatePicker();
        jLabel7 = new javax.swing.JLabel();
        tglAkhir = new org.jdesktop.swingx.JXDatePicker();
        btnCariTgl = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        tblJadwalByDate = new javax.swing.JTable();
        btnDetailTgl = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("jAdwal v0.1");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        tblJadwalHariIni.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null}
            },
            new String [] {
                "Kata Kunci", "Judul", "Status"
            }
        ));
        jScrollPane1.setViewportView(tblJadwalHariIni);

        jButton3.setText("Lihat Detail");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 505, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 314, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton3)
                .addContainerGap())
        );
        jTabbedPane1.addTab("Jadwal Hari Ini", jPanel1);

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Input Data Jadwal"));
        jLabel1.setText("Tanggal Peringatan :");

        jLabel2.setText("Kata Kunci :");

        jLabel3.setText("Judul :");

        jLabel4.setText("Konten :");

        tglWarningDate.setEditable(false);

        txtKataKunci.setEditable(false);

        txtJudul.setEditable(false);

        txtKonten.setColumns(20);
        txtKonten.setEditable(false);
        txtKonten.setRows(5);
        jScrollPane2.setViewportView(txtKonten);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(13, 13, 13)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE)
                    .addComponent(txtKataKunci, javax.swing.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE)
                    .addComponent(tglWarningDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtJudul, javax.swing.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(tglWarningDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtKataKunci, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtJudul, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE))
                .addContainerGap())
        );

        btnSimpan.setText("Simpan");
        btnSimpan.setEnabled(false);
        btnSimpan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSimpanActionPerformed(evt);
            }
        });

        btnBaru.setText("Baru");
        btnBaru.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBaruActionPerformed(evt);
            }
        });

        btnBatal.setText("Batal");
        btnBatal.setEnabled(false);
        btnBatal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBatalActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(btnBaru)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnBatal)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnSimpan)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSimpan)
                    .addComponent(btnBaru)
                    .addComponent(btnBatal))
                .addContainerGap())
        );
        jTabbedPane1.addTab("Buat Jadwal Baru", jPanel2);

        jLabel5.setText("Kata Kunci :");

        tblJadwalByKeyword.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null}
            },
            new String [] {
                "Kata Kunci", "Judul", "Status"
            }
        ));
        jScrollPane3.setViewportView(tblJadwalByKeyword);

        btnCari.setText("Cari");
        btnCari.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCariActionPerformed(evt);
            }
        });

        btnDetailByKey.setText("Lihat Detail");
        btnDetailByKey.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDetailByKeyActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtKeyword, javax.swing.GroupLayout.DEFAULT_SIZE, 334, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCari, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnDetailByKey, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(btnCari)
                    .addComponent(txtKeyword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnDetailByKey)
                .addGap(12, 12, 12))
        );
        jTabbedPane2.addTab("Berdasarkan Kata Kunci", jPanel5);

        jLabel6.setText("Dari Tanggal :");

        jLabel7.setText("Sampai Tanggal :");

        btnCariTgl.setText("Cari");
        btnCariTgl.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCariTglActionPerformed(evt);
            }
        });

        tblJadwalByDate.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null}
            },
            new String [] {
                "Kata Kunci", "Judul", "Status"
            }
        ));
        jScrollPane4.setViewportView(tblJadwalByDate);

        btnDetailTgl.setText("Lihat Detail");
        btnDetailTgl.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDetailTglActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tglAwal, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tglAkhir, javax.swing.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCariTgl, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnDetailTgl, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(tglAwal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(tglAkhir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCariTgl))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnDetailTgl)
                .addContainerGap())
        );
        jTabbedPane2.addTab("Berdasarkan Tanggal", jPanel6);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 505, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 343, Short.MAX_VALUE)
                .addContainerGap())
        );
        jTabbedPane1.addTab("Pencarian Jadwal", jPanel3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 530, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    private void btnDetailTglActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDetailTglActionPerformed
        if(tblJadwalByDate.getSelectedRow()<0){
            JOptionPane.showMessageDialog(this,"Silahkan pilih salah satu Jadwal");
        }else{
            Jadwal jadwal = (Jadwal)listJadwalByDate.get(tblJadwalByDate.getSelectedRow());
            DetailJadwal detail = new DetailJadwal(jadwal);
            detail.setVisible(true);
        }
    }//GEN-LAST:event_btnDetailTglActionPerformed
    
    private void btnCariTglActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCariTglActionPerformed
        JadwalManager mgr = new JadwalManager();
        try {
            listJadwalByDate = mgr.getListJadwalByDate(this.tglAwal.getDate(),this.tglAkhir.getDate());
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this,"Ups!, Pencarian data gagal...");
            ex.printStackTrace();
        }
        if(listJadwalByDate.size()>0){
            String[][] data = new String[listJadwalByDate.size()][3];
            for(int x=0;x<listJadwalByDate.size();x++){
                Jadwal jd = (Jadwal)listJadwalByDate.get(x);
                data[x][0] = jd.getKeyword();
                data[x][1] = jd.getTitle();
                if(jd.getStatus()==0) data[x][2]="Not Complete";
                else data[x][2] = "Completed";
            }
            String[] title = {"Kata Kunci","Title","Status"};
            DefaultTableModel model = new DefaultTableModel(data,title);
            tblJadwalByDate.setModel(model);
            jScrollPane4.setViewportView(tblJadwalByDate);
        }
    }//GEN-LAST:event_btnCariTglActionPerformed
    
    private void btnDetailByKeyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDetailByKeyActionPerformed
        if(tblJadwalByKeyword.getSelectedRow()<0){
            JOptionPane.showMessageDialog(this,"Silahkan pilih salah satu Jadwal");
        }else{
            Jadwal jadwal = (Jadwal)listJadwalByKeyword.get(tblJadwalByKeyword.getSelectedRow());
            DetailJadwal detail = new DetailJadwal(jadwal);
            detail.setVisible(true);
        }
    }//GEN-LAST:event_btnDetailByKeyActionPerformed
    
    private void btnCariActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCariActionPerformed
        JadwalManager mgr = new JadwalManager();
        
        try {
            listJadwalByKeyword = mgr.getListJadwalByKeyWord(this.txtKeyword.getText());
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this,"Ups!, Pencarian data gagal...");
            ex.printStackTrace();
        }
        if(listJadwalByKeyword.size()>0){
            String[][] data = new String[listJadwalByKeyword.size()][3];
            for(int x=0;x<listJadwalByKeyword.size();x++){
                Jadwal jd = (Jadwal)listJadwalByKeyword.get(x);
                data[x][0] = jd.getKeyword();
                data[x][1] = jd.getTitle();
                if(jd.getStatus()==0) data[x][2]="Not Complete";
                else data[x][2] = "Completed";
            }
            String[] title = {"Kata Kunci","Title","Status"};
            DefaultTableModel model = new DefaultTableModel(data,title);
            tblJadwalByKeyword.setModel(model);
            jScrollPane3.setViewportView(tblJadwalByKeyword);
        }
    }//GEN-LAST:event_btnCariActionPerformed
    
    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        loadJadwalHariIni();
    }//GEN-LAST:event_formWindowActivated
    
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        if(tblJadwalHariIni.getSelectedRow()<0){
            JOptionPane.showMessageDialog(this,"Silahkan pilih salah satu Jadwal");
        }else{
            Jadwal jadwal = (Jadwal)listJadwalHariIni.get(tblJadwalHariIni.getSelectedRow());
            DetailJadwal detail = new DetailJadwal(jadwal);
            detail.setVisible(true);
        }
    }//GEN-LAST:event_jButton3ActionPerformed
    
    private void btnSimpanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSimpanActionPerformed
        
        Jadwal jadwal = new Jadwal();
        jadwal.setPostDate(new Date());
        jadwal.setWarningDate(tglWarningDate.getDate());
        jadwal.setTitle(txtJudul.getText());
        jadwal.setKeyword(txtKataKunci.getText());
        jadwal.setContent(txtKonten.getText());
        try {
            mgr.insertJadwal(jadwal);
            JOptionPane.showMessageDialog(this,"Data Tersimpan");
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this,"Maaf, telah terjadi error.\nData gagal disimpan");
            ex.printStackTrace();
        }
        
        tglWarningDate.setEditable(false);
        txtKataKunci.setEditable(false);
        txtJudul.setEditable(false);
        txtKonten.setEditable(false);
        
        btnBaru.setEnabled(true);
        btnBatal.setEnabled(false);
        btnSimpan.setEnabled(false);
        
        txtKataKunci.setText("");
        txtJudul.setText("");
        txtKonten.setText("");
        loadJadwalHariIni();
    }//GEN-LAST:event_btnSimpanActionPerformed
    
    private void btnBatalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBatalActionPerformed
        tglWarningDate.setEditable(false);
        txtKataKunci.setEditable(false);
        txtJudul.setEditable(false);
        txtKonten.setEditable(false);
        
        btnBaru.setEnabled(true);
        btnBatal.setEnabled(false);
        btnSimpan.setEnabled(false);
        
        txtKataKunci.setText("");
        txtJudul.setText("");
        txtKonten.setText("");
    }//GEN-LAST:event_btnBatalActionPerformed
    
    private void btnBaruActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBaruActionPerformed
        tglWarningDate.setEditable(true);
        txtKataKunci.setEditable(true);
        txtJudul.setEditable(true);
        txtKonten.setEditable(true);
        
        btnBaru.setEnabled(false);
        btnBatal.setEnabled(true);
        btnSimpan.setEnabled(true);
        
        tglWarningDate.requestFocus();
    }//GEN-LAST:event_btnBaruActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBaru;
    private javax.swing.JButton btnBatal;
    private javax.swing.JButton btnCari;
    private javax.swing.JButton btnCariTgl;
    private javax.swing.JButton btnDetailByKey;
    private javax.swing.JButton btnDetailTgl;
    private javax.swing.JButton btnSimpan;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTabbedPane jTabbedPane2;
    private javax.swing.JTable tblJadwalByDate;
    private javax.swing.JTable tblJadwalByKeyword;
    private javax.swing.JTable tblJadwalHariIni;
    private org.jdesktop.swingx.JXDatePicker tglAkhir;
    private org.jdesktop.swingx.JXDatePicker tglAwal;
    private org.jdesktop.swingx.JXDatePicker tglWarningDate;
    private javax.swing.JTextField txtJudul;
    private javax.swing.JTextField txtKataKunci;
    private javax.swing.JTextField txtKeyword;
    private javax.swing.JTextArea txtKonten;
    // End of variables declaration//GEN-END:variables
    
}
